﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
/// <summary>
/// Summary description for clsBranchMasterDAL
/// </summary>
public class clsBranchMasterDAL
{
    InstantNaukriDataContextDataContext objInstantNaukriDataContextDataContext = new InstantNaukriDataContextDataContext();
	public clsBranchMasterDAL()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public List<IN_TB_BRANCH_MST> GetAllBranch()
    {
        try
        {
            List<IN_TB_BRANCH_MST> objIN_TB_BRANCH_MST = new List<IN_TB_BRANCH_MST>();
            objIN_TB_BRANCH_MST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_BRANCH_MSTs
                                 select obj).ToList();
            return objIN_TB_BRANCH_MST;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public IN_TB_BRANCH_MST GetBranchById(int ID)
    {
        try
        {
            IN_TB_BRANCH_MST objIN_TB_BRANCH_MST = new IN_TB_BRANCH_MST();
            objIN_TB_BRANCH_MST= (from obj in objInstantNaukriDataContextDataContext.IN_TB_BRANCH_MSTs
                                 where obj.ID == ID
                                 select obj).SingleOrDefault();
            return objIN_TB_BRANCH_MST;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public IN_TB_BRANCH_MST GetBranchByUserId(int UserId)
    {
        try
        {
            IN_TB_BRANCH_MST objIN_TB_BRANCH_MST = new IN_TB_BRANCH_MST();
            objIN_TB_BRANCH_MST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_BRANCH_MSTs
                                 where obj.USER_ID == UserId
                                 select obj).SingleOrDefault();
            return objIN_TB_BRANCH_MST;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public int SaveBranchMst(IN_TB_BRANCH_MST objIN_TB_BRANCH_MST)
    {
        try
        {
            IN_TB_BRANCH_MST objIN_TB_BRANCH_MSTD = new IN_TB_BRANCH_MST();
            objIN_TB_BRANCH_MSTD = (from obj in objInstantNaukriDataContextDataContext.IN_TB_BRANCH_MSTs
                                      where obj.ID == objIN_TB_BRANCH_MST.ID
                                      select obj).SingleOrDefault();
            if (objIN_TB_BRANCH_MSTD != null)
            {
                objIN_TB_BRANCH_MSTD.ID = objIN_TB_BRANCH_MST.ID;
                objIN_TB_BRANCH_MSTD.USER_ID = objIN_TB_BRANCH_MST.USER_ID;
                objIN_TB_BRANCH_MSTD.BRANCH_DESCRIPTION = objIN_TB_BRANCH_MST.BRANCH_NAME;
                objIN_TB_BRANCH_MSTD.BRANCH_DESCRIPTION = objIN_TB_BRANCH_MST.BRANCH_DESCRIPTION;
                objIN_TB_BRANCH_MSTD.EMAIL = objIN_TB_BRANCH_MST.EMAIL;
                objIN_TB_BRANCH_MSTD.MOBILE = objIN_TB_BRANCH_MST.MOBILE;
                objIN_TB_BRANCH_MSTD.PHONE = objIN_TB_BRANCH_MST.PHONE;
                objIN_TB_BRANCH_MSTD.STATUS = objIN_TB_BRANCH_MST.STATUS;
                objIN_TB_BRANCH_MSTD.CREATED_BY = objIN_TB_BRANCH_MST.CREATED_BY;
                objIN_TB_BRANCH_MSTD.CREATED_ON = objIN_TB_BRANCH_MST.CREATED_ON;
                objIN_TB_BRANCH_MSTD.MODIFIED_BY = objIN_TB_BRANCH_MST.MODIFIED_BY;
                objIN_TB_BRANCH_MSTD.MODIFIED_ON = objIN_TB_BRANCH_MST.MODIFIED_ON;
                objIN_TB_BRANCH_MSTD.DOWNLOAD_TILL = objIN_TB_BRANCH_MST.DOWNLOAD_TILL;
                objIN_TB_BRANCH_MSTD.LOGIN_TILL = objIN_TB_BRANCH_MST.LOGIN_TILL;
                objInstantNaukriDataContextDataContext.SubmitChanges();
                return objIN_TB_BRANCH_MSTD.ID;
            }
            else
            {
                objInstantNaukriDataContextDataContext.IN_TB_BRANCH_MSTs.InsertOnSubmit(objIN_TB_BRANCH_MST);
                objInstantNaukriDataContextDataContext.SubmitChanges();
                int NewID = (from obj in objInstantNaukriDataContextDataContext.IN_TB_BRANCH_MSTs
                             select obj.ID).Max();
                return NewID;
            }
        }
        catch (Exception)
        {

            throw;
        }
    }

    public void DeleteBranch(int BranchId)
    {
        try
        {
            IN_TB_BRANCH_MST objIN_TB_BRANCH_MST = new IN_TB_BRANCH_MST();
            objIN_TB_BRANCH_MST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_BRANCH_MSTs
                                     where obj.ID == BranchId
                                     select obj).SingleOrDefault();
            if (objIN_TB_BRANCH_MST != null)
            {
                objInstantNaukriDataContextDataContext.IN_TB_BRANCH_MSTs.DeleteOnSubmit(objIN_TB_BRANCH_MST);
                objInstantNaukriDataContextDataContext.SubmitChanges();
            }

        }
        catch (Exception)
        {

            throw;
        }
    }

    public List<clsGetBranchInfo> GetAllBranchFullInfo()
    {
        try
        {
            List<clsGetBranchInfo> objclsGetBranchInfo = new List<clsGetBranchInfo>();
            objclsGetBranchInfo = new List<clsGetBranchInfo>();
            objclsGetBranchInfo = (from obj in objInstantNaukriDataContextDataContext.IN_TB_BRANCH_MSTs
                                      join  objUser in objInstantNaukriDataContextDataContext.IN_TB_USERs on obj.USER_ID equals objUser.ID
                                      where objUser.ROLEID == 5
                                      select new clsGetBranchInfo

                                      {
                                          USERID = (int)objUser.ID,
                                          ID = (int)obj.ID,
                                          BRANCH_NAME = obj.BRANCH_NAME,
                                          BRANCH_DESCRIPTION = obj.BRANCH_DESCRIPTION,
                                          Download_Till = (DateTime)obj.DOWNLOAD_TILL,
                                          Login_Till = (DateTime)obj.LOGIN_TILL,
                                          EMAIL = objUser.EMAIL,
                                          MOBILE = objUser.MOBILE,
                                          NAME = objUser.NAME,
                                          PHONE = obj.PHONE,
                                          DOB = (DateTime)objUser.DOB,
                                          EMPLOYER_NAME = objUser.NAME,

                                      }
                                          ).ToList();




            return objclsGetBranchInfo;



        }
        catch (Exception)
        {

            throw;
        }
    }



}
   